home *** CD-ROM | disk | FTP | other *** search
- Path: news.mindlink.net!news
- From: genew@mindlink.bc.ca (Gene Wirchenko)
- Newsgroups: comp.lang.c
- Subject: Re: char* to char array[] ?
- Date: Sat, 13 Jan 1996 05:51:32 GMT
- Organization: MIND LINK! - British Columbia, Canada
- Message-ID: <4d7hb4$gak@fountain.mindlink.net>
- References: <4d4n9s$9uv@ixnews2.ix.netcom.com> <1996Jan13.013852.19365@hns.com>
- NNTP-Posting-Host: line078.nwm.mindlink.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- Ralph Sweitzer <t_rsweitzer> wrote:
-
- >Try something like this it should work.
-
- >/* prototype */
- >char *called_finction(void);
-
- >void calling_function(void)
- >{
- > char *ptr;
- > ptr = called_function();
- >}
-
- >char *called_function(void)
- >{
- > char buf[] = {"hello world"};
- > return((char *)buf);
- >}
- >--
- >Ralph Sweitzer
-
- No, it won't work. The storage for buf[] in called_function()
- will be released when that function terminates. This will make the
- returned pointer invalid.
-
- Have a look at the FAQ.
-
- Sincerely,
-
- Gene Wirchenko
-
- C Pronunciation Guide:
- y=x++; "wye equals ex plus plus semicolon"
- x=x++; "ex equals ex doublecross semicolon"
-
-